from superdice.libs.diceConfigs import configFile
from superdice.libs.playerExtras import getPlayer
from superdice.superdice import registerRoll, unregisterRoll, players

def es_map_start(ev):
    cfgData.execute()

def unload():
    unregisterRoll(diceRoll)

def player_spawn(ev):
    players[ev['userid']]['squish'] = False

def player_hurt(ev):
    userid = ev['userid']
    attacker = ev['attacker']
    if not players[userid]['squish'] or int(ev['es_userdead']) or ev['weapon'] == 'hurt_squishy':
        return

    if not attacker in players:
        attacker = None

    damage = int(round(float(ev['dmg_health']) * float(multi)))
    if damage < 1:
        return

    getPlayer(userid).damagePlayer(damage, userid=attacker, weapon='hurt_squishy')

def diceRoll(userid, player, eplayer):
    players[userid]['squish'] = True

cfgData = configFile('dice_squishy')
multi = cfgData.cvar('superdice_cfg_squishy_multiplier', 0.8, 'What is the multiplier for the damage based on damage gotten that the player will recieve.')
cfgData.write()
cfgData.execute()

registerRoll(diceRoll, 'squishy')
